package com.dcliment.display.gui
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 *  :: SIMPLE Play Pause Button ::
	 * 
	 * Frame one is PLAY
	 * Frame two is PAUSE
	 *  
	 * @author dcliment
	 * version 1.0
	 * 
	 */	
	
	public class SimplePPButton extends MovieClip
	{
		public static var PLAY_CLICKED:String = "play_clicked"; 
		public static var PAUSE_CLICKED:String = "pause_clicked"; 
		
		public function SimplePPButton()
		{
			this.gotoAndStop(1);
			
			enable();
		}
		//
		// Public functions
		//
		public function enable():void
		{
			
			this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
			this.mouseEnabled = true;
			this.buttonMode = true;
			
		}
		public function disable():void
		{	
			this.removeEventListener(MouseEvent.CLICK, onClick);
			
			this.mouseEnabled = false;
			this.buttonMode = false;
		}
		
		public function playState():void
		{
			this.gotoAndStop(2);
		}
		public function pauseState():void
		{
			this.gotoAndStop(1);
		}
		
		//
		// Private Functions
		//
		protected function onClick(e:MouseEvent):void
		{
			
			if(this.currentFrame == 1)
			{
				playState();
				dispatchEvent(new Event(SimplePPButton.PLAY_CLICKED));
			}
			else if(this.currentFrame == 2)
			{
				pauseState();
				dispatchEvent(new Event(SimplePPButton.PAUSE_CLICKED));
			}
		}
		
	}
}